public class MyStack {
    private Object[] arr;
    private int topPointer = -1; //栈顶位置
    public MyStack(int cap){
        this.arr = new Object[cap];
    }
    public void push(Object ele){//压栈
        if(this.isFull())throw new RuntimeException("栈已满！不允许压入元素");
        arr[++topPointer] = ele;
    }
    public Object pop(){//弹栈
        if(this.isEmpty())throw new RuntimeException("栈已空！不允许弹出元素");
        Object ele = arr[topPointer];
        arr[topPointer] = null;
        topPointer--;
        return ele;
    }
    public int size(){
        return topPointer+1;
    }
    public boolean isFull(){//是否栈满
        return topPointer == arr.length-1;
    }
    public boolean isEmpty(){//是否栈空
        return topPointer == -1;
    }
}
